package com.xcjh.googlemix

import android.os.Bundle
import android.view.KeyEvent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.xcjh.base_lib.Constants
import com.xcjh.base_lib.base.activity.BaseActivity
import com.xcjh.base_lib.route.RouteCenter
import com.xcjh.base_lib.utils.myToast
import com.xcjh.googlemix.databinding.ActivityMainBinding
import com.xcjh.googlemix.viewmodel.CheckoutViewModel

/**
 * Checkout implementation for the app
 */
class MainActivity : BaseActivity() {


    private val model: CheckoutViewModel by viewModels()

    private lateinit var layoutBinding: ActivityMainBinding

    /**
     *
     * @see AppCompatActivity.onCreate
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        layoutBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(layoutBinding.root)
        setOnClick()
    }

    private fun setOnClick() {
        layoutBinding.btnAd.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Ad.A_Ad_MAIN)
        }
        layoutBinding.btnRecharge.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Recharge.A_Recharge_MAIN)
        }

        layoutBinding.btnLogin.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Login.A_Login_MAIN)
        }
        layoutBinding.btnRanking.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Ranking.A_Ranking_MAIN)
        }

        layoutBinding.btnAnalytics.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Analytic.A_Analytic_MAIN)
        }
        layoutBinding.btnShare.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Share.A_Share_MAIN)
        }

        layoutBinding.btnSms.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Sms.A_Sms_MAIN)
        }
        layoutBinding.btnPush.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Push.A_Push_MAIN)
        }
        layoutBinding.btnWs.setOnClickListener {
            RouteCenter.navigate(Constants.Router.Ws.A_Ws_MAIN)
        }
    }
    private var exitTime: Long = 0
    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
            if (System.currentTimeMillis() - exitTime > 2000) {
                myToast("再按一次退出程序")
                exitTime = System.currentTimeMillis()
            } else {
                finish()
            }
            return true
        }
        return super.onKeyDown(keyCode, event)
    }


}